<?php
namespace App\Admin\Renderable;
use App\Models\WxSearch;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class SearchRender extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new WxSearch(), function (Grid $grid) {
            global $__MINI_GLOBAL_TENANT_ID__;
            if($__MINI_GLOBAL_TENANT_ID__ > 0){
                $grid->model()->where('tenant_id', '=', $__MINI_GLOBAL_TENANT_ID__);
            }
            $grid->quickSearch(['id','search_content', 'user.user_name'])->placeholder('搜索id，内容，用户名...')->width(35);
            $grid->column('id')->sortable();
            $grid->column('user.user_avatar','头像')->image('',30,30);
            $grid->column('user.user_name','用户');
            $grid->column('search_content')->label();
            $grid->column('is_hot')->switch();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('is_hot')->select([0=>'否',1=>'是']);
            });
            $grid->model()->orderBy('id', 'desc');
            $grid->disableBatchActions();
            $grid->disableActions();
        });
    }
}
